package com.ysyx.ysyx_payorder.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.ysyx.ysyx_payorder.dto.BaseDto;
import com.ysyx.ysyx_payorder.qo.PayOrderQo;
import com.ysyx.ysyx_payorder.service.PayService;
import com.ysyx.ysyx_payorder.utils.QrCoreUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.UnsupportedEncodingException;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:郭宇轩
 * @create:2023/4/17 20:38
 */
@RestController
public class AlipayController {

    @Autowired
    public PayService payService;

    @RequestMapping(value = "/payment",method = RequestMethod.POST)
    public BaseDto getOrderInfo(@RequestBody PayOrderQo payOrderQo) throws AlipayApiException {
        System.out.println("order=="+payOrderQo.getOrderId());
        BaseDto baseDto = payService.payment(payOrderQo.getOrderId());
        return baseDto;
    }

    @RequestMapping("/notify")
    public BaseDto notify_url(HttpServletRequest request) throws AlipayApiException, UnsupportedEncodingException {
        String message = payService.payCallback(request);
        return new BaseDto(0,message,null);
    }
}
